<template>
	<view class="page">
<!-- 		<uni-segmented-control :current="current" :values="items.map(v=>v.title)" @clickItem="onClickItem"
			styleType="text" activeColor="#e68a00">
		</uni-segmented-control>
		<view class="content">
			<view v-show="current === 0">
				<message></message>
			</view>
			<view v-show="current === 1">
				<schedule></schedule>
			</view>
		</view> -->
		<view class="message_item" v-for="(item,index) in messageList" :key="item.title"
			@click="clickFun(path[index].url)">
			<image v-if="item.img" :src="getImageUrl(item.img)"></image>
			<view class="message_title">{{item.title}}</view>
		</view>
	</view>
</template>

<script>

	import message from "../../components/message/message/message";
	import schedule from "../../components/message/schedule/schedule";
	import uniSegmentedControl from "../../uni_modules/uni-segmented-control/components/uni-segmented-control/uni-segmented-control";
	
	import {
		getHeaderList
	} from '@/api/home'
	
	export default {
		components: {
			message,
			schedule,
			uniSegmentedControl
		},
		data() {
			return {
				messageList: [{
						title: "服务提醒",
						img: ""
					},
					{
						title: "时间币助手",
						img: ""
					},
					{
						title: "审核通知",
						img: ""
					},
					{
						title: "系统消息",
						img: ""
					}
				],
				path: [
					{url: '/pages/message/message-list/message-list?msgtype=1'},
					{url: '/pages/message/message-list/message-list?msgtype=2'},
					{url: '/pages/message/message-list/message-list?msgtype=3'},
					{url: '/pages/message/message-list/message-list?msgtype=3'}
				],
				items: [{
						title: "消息"
					},
					{
						title: "待办"
					}
				],
				current: 0,
				params: {
					// encryptedData:
					// signature:
					// rawData:
					// iv:
					// code:
				}
			}
		},
		onLoad() {
			if(uni.getStorageSync('token') === null || uni.getStorageSync('token') == ""){
				uni.redirectTo({
					url:"/pages/login/index"
				})
			} else {
				this.getMessageIcon();
			}
		},
		methods: {
			getMessageIcon() {
				let token = uni.getStorageSync('token');
				getHeaderList({
					'token': token,
					'typeName': 'newslist'
				}).then(res => {
					console.log("图标：", res);
					this.messageList = res.data;
				})
			},
			getImageUrl(src) {
				return this.domain + src;
			},
			clickFun(url) {
				wx.navigateTo({
				    url: url
				})
			},
			
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex;
				}
			}

		}
	}
</script>

<style lang="scss">
	.page {
		height: 100%;
		width: 100vw;
		min-height: 100vh;
		background-color: $global_bg_color;
		padding-top: 1rpx;
	}
	.message_item {
		margin: 0 8rpx;
		height: 150rpx;
		display: flex;
		margin-top: 2rpx;
		align-items: center;
		background-color: #FFFFFF;
		border-radius: 8rpx;
	
		image {
			height: 100rpx;
			width: 100rpx;
			border-radius: 50rpx;
			margin: 0rpx 10rpx;
		}
	
		;
	
		.message_title {
			margin-left: 15rpx;
			font-size: 35rpx;
		}
	}
</style>
